package com.luxsoft.siipap.migracion;

import java.beans.PropertyDescriptor;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSource;
import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils;

import com.luxsoft.siipap.model.core.Producto;


public class MigrationUtils {
	
	protected static Logger logger=Logger.getLogger(MigrationUtils.class);
	
	/**
	 * jdbc.driverClassName=oracle.jdbc.OracleDriver
		jdbc.url=jdbc:oracle:thin:@ser-ofi-d:1521:pruebas
		jdbc.username=siipap
		jdbc.password=sys=org.hibernate.dialect.Oracle10gDialect

	 * @return
	 */
	public static  DataSource createMigrationDataSource(){
		BasicDataSource ds=new BasicDataSource();
		ds.setDriverClassName("oracle.jdbc.OracleDriver");
		ds.setUrl("jdbc:oracle:thin:@ser-ofi-d:1521:pruebas");
		ds.setPassword("sys");
		ds.setUsername("siipap");
		return ds;
	}
	
	public static void printProperties(Class clazz){
		final String patter="<entry key=\"{0}\" \tvalue=\"{1}\" />";
		PropertyDescriptor[] desc=BeanUtils.getPropertyDescriptors(clazz);
		List<PropertyDescriptor> descriptors=Arrays.asList(desc);
		Collections.sort(descriptors, new Comparator<PropertyDescriptor>(){
			public int compare(PropertyDescriptor o1, PropertyDescriptor o2) {
				return o1.getName().compareTo(o2.getName());
			}
		});
		for(PropertyDescriptor p:descriptors){
			System.out.println(MessageFormat.format(patter, p.getName(),p.getName().toUpperCase()));
		}
		
	}
	
	public static void main(String[] args) {
		printProperties(Producto.class);
	}

}
